package server;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.sql.SQLException;


public class serverMain {

	static int clientnum = 0;
	static final int PORT = 33333;
	
	public static void main(String[] args) {
		ServerSocket serverSocket = null;
		ServerSocket serverSocket2 = null;
		boolean listening = true;
		Global.init();//从location.txt中读取初始地理位置列表
		try {
			Global.serverDAO.connectToSQL();
			Global.serverDAO.clear();
		} catch (SQLException e1) {		
			e1.printStackTrace();
		}
		try {
			serverSocket = new ServerSocket(PORT);
			int temp=1;
			while (listening){
				Socket socket = serverSocket.accept();
				Socket socket2 =new Socket(socket.getInetAddress(),(PORT+ temp)); 
			    new Client(socket,socket2,clientnum).start();
			    temp++;
			    //new Client(socket,clientnum).start();
				clientnum ++;
			}
			
			serverSocket.close();
			
		} catch (IOException e) {
			e.printStackTrace();
			System.out.println("Could not listen on prot: "+PORT+".\n");
			System.exit(-1);
		}
	}

}

